<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>心灵笔触</title>
    <link rel="stylesheet" href="css/conmmon.css">
    <link rel="stylesheet" href="css/login.css">
    <script src="js/jquery.min.js"></script>
</head>

<body>
    <!-- 导航栏 -->
    <div class="nav"> 
        <img src="img/logo2.jpg" alt="">
        <span class="title">心灵笔触</span>
        <!-- 用来占据中间位置 -->
        <span class="spacer"></span>
        <a href="blog_list.html?pindex=1">主页</a>
        <a href="reg.html">注册</a>
    </div>
    <!-- 版心 -->
    <div class="login-container">
        <!-- 中间的登陆框 -->
        <div class="login-dialog">
            <h3>找回密码</h3>
            <div class="row">
                <span>用户名</span>
                <input type="text" id="username">
            </div>
            <div class="row">
                <span>输入新密码</span>
                <input type="text" id="password">
            </div>
            <div class="row">
                <a href="reg.html" style="text-decoration: none;color:rgb(116, 117, 119) ;">没密码，去注册</a>
            </div>
            <div class="row">
                <button id="submit" onclick="dologin()">重 置</button>
            </div>
        </div>
    </div>
    <script>
        // 执行登录操作
        function dologin() {
            // 1. 效验参数
            var username = jQuery("#username");
            var password = jQuery("#password");
            if(username.val().trim() == "") {
                alert("请先输入用户名！");
                username.focus();
                return false;
            }
            if(password.val().trim() == "") {
                alert("请输入新密码！");
                password.focus();
                return false;
            }   
            // 2. 将数据提交给后端
            jQuery.ajax({
                url:"/user/recover",
                type:"POST",
                data:{
                    "username":username.val(),
                    "password":password.val()
                },
                // 3. 将后端返回的结果展示给用户
                success:function(res) {
                    if(res.code==200 && res.data==1) {
                        alert("密码更改成功，请重新登录！");
                        // 跳转到 我的文章管理页
                        location.href = "login.html";
                    }else {
                        alert("该用户不存在！" + res.msg);
                    }
                }
            });

           
        }
    </script>
</body>

</html>